<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=11"/>
<meta name="generator" content="Doxygen 1.9.6"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>AngelScript: Context manager</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
  $(document).ready(function() { init_search(); });
/* @license-end */
</script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr id="projectrow">
  <td id="projectlogo"><img alt="Logo" src="aslogo_small.png"/></td>
  <td id="projectalign">
   <div id="projectname">AngelScript
   </div>
  </td>
    <td>        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <span id="MSearchSelect"                onmouseover="return searchBox.OnSearchSelectShow()"                onmouseout="return searchBox.OnSearchSelectHide()">&#160;</span>
          <input type="text" id="MSearchField" value="" placeholder="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.svg" alt=""/></a>
          </span>
        </div>
</td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.9.6 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
var searchBox = new SearchBox("searchBox", "search/",'.html');
/* @license-end */
</script>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
      <div id="nav-sync" class="sync"></div>
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
$(document).ready(function(){initNavTree('doc_addon_ctxmgr.html',''); initResizable(); });
/* @license-end */
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<div id="MSearchResults">
<div class="SRPage">
<div id="SRIndex">
<div id="SRResults"></div>
<div class="SRStatus" id="Loading">Loading...</div>
<div class="SRStatus" id="Searching">Searching...</div>
<div class="SRStatus" id="NoMatches">No Matches</div>
</div>
</div>
</div>
</div>

<div><div class="header">
  <div class="headertitle"><div class="title">Context manager </div></div>
</div><!--header-->
<div class="contents">
<div class="textblock"><p><b>Path:</b> /sdk/add_on/contextmgr/</p>
<p>The <code>CContextMgr</code> is a class designed to aid the management of multiple simultaneous scripts executing in parallel. It supports both <a class="el" href="doc_adv_concurrent.html">concurrent script threads</a> and <a class="el" href="doc_adv_coroutine.html">co-routines</a>.</p>
<p>If the application doesn't need multiple contexts, i.e. all scripts that are executed always complete before the next script is executed, then this class is not necessary.</p>
<p>The context manager uses <a class="el" href="classas_i_script_engine.html#a14fcb46b5193d8fd43680a5513d60200">asIScriptEngine::RequestContext</a> to take advantage of any context callbacks registered with the engine, e.g. for debugging or pooling.</p>
<p>Multiple context managers can be used, for example when you have a group of scripts controlling in-game objects, and another group of scripts controlling GUI elements, then each of these groups may be managed by different context managers.</p>
<p>Observe that the context manager class hasn't been designed for multi-threading, so you need to be careful if your application needs to execute scripts from multiple threads.</p>
<dl class="section see"><dt>See also</dt><dd>The samples <a class="el" href="doc_samples_concurrent.html">Concurrent scripts</a> and <a class="el" href="doc_samples_corout.html">Co-routines</a> for uses</dd></dl>
<h1><a class="anchor" id="doc_addon_ctxmgr_1"></a>
Public C++ interface</h1>
<div class="fragment"><div class="line"><span class="keyword">class </span>CContextMgr</div>
<div class="line">{</div>
<div class="line"><span class="keyword">public</span>:</div>
<div class="line">  CContextMgr();</div>
<div class="line">  ~CContextMgr();</div>
<div class="line"> </div>
<div class="line">  <span class="comment">// Set the function that the manager will use to obtain the time in milliseconds.</span></div>
<div class="line">  <span class="keywordtype">void</span> SetGetTimeCallback(TIMEFUNC_t func);</div>
<div class="line"> </div>
<div class="line">  <span class="comment">// Registers the following:</span></div>
<div class="line">  <span class="comment">//</span></div>
<div class="line">  <span class="comment">//  void sleep(uint milliseconds)</span></div>
<div class="line">  <span class="comment">//</span></div>
<div class="line">  <span class="comment">// The application must set the get time callback for this to work</span></div>
<div class="line">  <span class="keywordtype">void</span> RegisterThreadSupport(<a class="code hl_class" href="classas_i_script_engine.html">asIScriptEngine</a> *engine);</div>
<div class="line"> </div>
<div class="line">  <span class="comment">// Registers the following:</span></div>
<div class="line">  <span class="comment">//</span></div>
<div class="line">  <span class="comment">//  funcdef void coroutine(dictionary@)</span></div>
<div class="line">  <span class="comment">//  void createCoRoutine(coroutine @func, dictionary @args)</span></div>
<div class="line">  <span class="comment">//  void yield()</span></div>
<div class="line">  <span class="keywordtype">void</span> RegisterCoRoutineSupport(<a class="code hl_class" href="classas_i_script_engine.html">asIScriptEngine</a> *engine);</div>
<div class="line"> </div>
<div class="line">  <span class="comment">// Create a new context, prepare it with the function, then return </span></div>
<div class="line">  <span class="comment">// it so that the application can pass the argument values. The context</span></div>
<div class="line">  <span class="comment">// will be released by the manager after the execution has completed.</span></div>
<div class="line">  <span class="comment">// Set keepCtxAfterExecution to true if the application needs to retrieve</span></div>
<div class="line">  <span class="comment">// information from the context after it the script has finished. </span></div>
<div class="line">  <a class="code hl_class" href="classas_i_script_context.html">asIScriptContext</a> *AddContext(<a class="code hl_class" href="classas_i_script_engine.html">asIScriptEngine</a> *engine, <a class="code hl_class" href="classas_i_script_context.html">asIScriptContext</a> *func, <span class="keywordtype">bool</span> keepCtxAfterExecution = <span class="keyword">false</span>);</div>
<div class="line"> </div>
<div class="line">  <span class="comment">// If the context was kept after the execution, this method must be </span></div>
<div class="line">  <span class="comment">// called when the application is done with the context so it can be</span></div>
<div class="line">  <span class="comment">// returned to the pool for reuse.</span></div>
<div class="line">  <span class="keywordtype">void</span> DoneWithContext(<a class="code hl_class" href="classas_i_script_context.html">asIScriptContext</a> *ctx);</div>
<div class="line">  </div>
<div class="line">  <span class="comment">// Create a new context, prepare it with the function, then return</span></div>
<div class="line">  <span class="comment">// it so that the application can pass the argument values. The context</span></div>
<div class="line">  <span class="comment">// will be added as a co-routine in the same thread as the currCtx.</span></div>
<div class="line">  <a class="code hl_class" href="classas_i_script_context.html">asIScriptContext</a> *AddContextForCoRoutine(<a class="code hl_class" href="classas_i_script_context.html">asIScriptContext</a> *currCtx, <a class="code hl_class" href="classas_i_script_context.html">asIScriptContext</a> *func);</div>
<div class="line"> </div>
<div class="line">  <span class="comment">// Execute each script that is not currently sleeping. The function returns after </span></div>
<div class="line">  <span class="comment">// each script has been executed once. The application should call this function</span></div>
<div class="line">  <span class="comment">// for each iteration of the message pump, or game loop, or whatever.</span></div>
<div class="line">  <span class="comment">// Returns the number of scripts still in execution.</span></div>
<div class="line">  <span class="keywordtype">int</span> ExecuteScripts();</div>
<div class="line"> </div>
<div class="line">  <span class="comment">// Put a script to sleep for a while</span></div>
<div class="line">  <span class="keywordtype">void</span> SetSleeping(<a class="code hl_class" href="classas_i_script_context.html">asIScriptContext</a> *ctx, <a class="code hl_typedef" href="angelscript_8h.html#ac8186f029686800b7ce36bde4a55c815">asUINT</a> milliSeconds);</div>
<div class="line"> </div>
<div class="line">  <span class="comment">// Switch the execution to the next co-routine in the group.</span></div>
<div class="line">  <span class="comment">// Returns true if the switch was successful.</span></div>
<div class="line">  <span class="keywordtype">void</span> NextCoRoutine();</div>
<div class="line"> </div>
<div class="line">  <span class="comment">// Abort all scripts</span></div>
<div class="line">  <span class="keywordtype">void</span> AbortAll();</div>
<div class="line">};</div>
<div class="ttc" id="aangelscript_8h_html_ac8186f029686800b7ce36bde4a55c815"><div class="ttname"><a href="angelscript_8h.html#ac8186f029686800b7ce36bde4a55c815">asUINT</a></div><div class="ttdeci">unsigned int asUINT</div><div class="ttdoc">32 bit unsigned integer</div><div class="ttdef"><b>Definition:</b> angelscript.h:610</div></div>
<div class="ttc" id="aclassas_i_script_context_html"><div class="ttname"><a href="classas_i_script_context.html">asIScriptContext</a></div><div class="ttdoc">The interface to the virtual machine.</div><div class="ttdef"><b>Definition:</b> angelscript.h:2735</div></div>
<div class="ttc" id="aclassas_i_script_engine_html"><div class="ttname"><a href="classas_i_script_engine.html">asIScriptEngine</a></div><div class="ttdoc">The engine interface.</div><div class="ttdef"><b>Definition:</b> angelscript.h:1102</div></div>
</div><!-- fragment --><h1><a class="anchor" id="doc_addon_ctxmgr_2"></a>
Public script interface</h1>
<dl class="section see"><dt>See also</dt><dd><a class="el" href="doc_script_stdlib_coroutine.html">Co-routines</a> </dd></dl>
</div></div><!-- contents -->
</div><!-- PageDoc -->
</div><!-- doc-content -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
  <ul>
    <li class="footer">Generated on Sun May 21 2023 10:12:39 for AngelScript by <a href="https://www.doxygen.org/index.html"><img class="footer" src="doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.9.6 </li>
  </ul>
</div>
</body>
</html>
